version 6.0 
#delimit ;
/* read data */
infix 
   idnum 1-5
   rlfrt 6-7
   ragri 8-9
   renvi 10-11
   rimmi 12-13
   rpriv 14-15
   ralco 16-17
   rcrim 18-19
   p_lfrt1 20-21
   p_agri1 22-23
   p_envi1 24-25
   p_immi1 26-27
   p_priv1 28-29
   p_alco1 30-31                                   
   p_crim1 32-33
   p_lfrt2 34-35
   p_agri2 36-37
   p_envi2 38-39
   p_immi2 40-41
   p_priv2 42-43
   p_alco2 44-45
   p_crim2 46-47
   p_lfrt3 48-49
   p_agri3 50-51
   p_envi3 52-53
   p_immi3 54-55
   p_priv3 56-57
   p_alco3 58-59
   p_crim3 60-61
   p_lfrt4 62-63
   p_agri4 64-65
   p_envi4 66-67
   p_immi4 68-69
   p_priv4 70-71
   p_alco4 72-73
   p_crim4 74-75
   p_lfrt5 76-77
   p_agri5 78-79
   p_envi5 80-81
   p_immi5 82-83
   p_priv5 84-85
   p_alco5 86-87
   p_crim5 88-89
   p_lfrt6 90-91
   p_agri6 92-93
   p_envi6 94-95
   p_immi6 96-97
   p_priv6 98-99
   p_alco6 100-101
   p_crim6 102-103
   p_lfrt7 104-105
   p_agri7 106-107
   p_envi7 108-109
   p_immi7 110-111
   p_priv7 112-113
   p_alco7 114-115
   p_crim7 116-117
   symp1  118-120
   symp2  121-123
   symp3  124-126
   symp4  127-129
   symp5  130-132
   symp6  133-135
   symp7  136-138
   plfrt1 139-146
   pagri1 147-154
   penvi1 155-162
   pimmi1 163-170
   ppriv1 171-178
   palco1 179-186                                 
   pcrim1 187-194
   plfrt2 195-202
   pagri2 203-210
   penvi2 211-218
   pimmi2 219-226
   ppriv2 227-234
   palco2 235-242
   pcrim2 243-250
   plfrt3 251-258
   pagri3 259-266
   penvi3 267-274
   pimmi3 275-282
   ppriv3 283-290
   palco3 291-298
   pcrim3 299-306
   plfrt4 307-314
   pagri4 315-322
   penvi4 323-330
   pimmi4 331-338
   ppriv4 339-346
   palco4 347-354
   pcrim4 355-362
   plfrt5 363-370
   pagri5 371-378
   penvi5 379-386
   pimmi5 387-394
   ppriv5 395-402
   palco5 403-410
   pcrim5 411-418
   plfrt6 419-426
   pagri6 427-434
   penvi6 435-442
   pimmi6 443-450
   ppriv6 451-458
   palco6 459-466
   pcrim6 467-474
   plfrt7 475-482
   pagri7 483-490
   penvi7 491-498
   pimmi7 499-506
   ppriv7 507-514
   palco7 515-522
   pcrim7 523-530

using c:\stata\data\valg89AldMckSTATAV1.raw;

replace rlfrt=rlfrt - 5.5 ;
replace ragri=ragri - 5.5 ;
replace renvi=renvi - 5.5 ;
replace rimmi=rimmi - 5.5 ;
replace rpriv=rpriv - 5.5 ;
replace ralco=ralco - 5.5 ;
replace rcrim=rcrim - 5.5 ;

gen penalty1=1.541; 
gen penalty2=0.0;
gen penalty3=0.0;
gen penalty4=0.0;
gen penalty5=0.0;
gen penalty6=0.0;
gen penalty7=3.931; 

gen rlnlfrt=rlfrt*rlfrt ;
gen rlnagri=ragri*ragri ;
gen rlnenvi=renvi*renvi ;
gen rlnimmi=rimmi*rimmi ;
gen rlnpriv=rpriv*rpriv ;
gen rlnalco=ralco*ralco ;
gen rlncrim=rcrim*rcrim ;

replace plfrt1=plfrt1 - 5.5 ;
replace pagri1=pagri1 - 5.5 ;
replace penvi1=penvi1 - 5.5 ;
replace pimmi1=pimmi1 - 5.5 ;
replace ppriv1=ppriv1 - 5.5 ;
replace palco1=palco1 - 5.5 ;
replace pcrim1=pcrim1 - 5.5 ;

replace plfrt2=plfrt2 - 5.5 ;
replace pagri2=pagri2 - 5.5 ;
replace penvi2=penvi2 - 5.5 ;
replace pimmi2=pimmi2 - 5.5 ;
replace ppriv2=ppriv2 - 5.5 ;
replace palco2=palco2 - 5.5 ;
replace pcrim2=pcrim2 - 5.5 ;

replace plfrt3=plfrt3 - 5.5 ;
replace pagri3=pagri3 - 5.5 ;
replace penvi3=penvi3 - 5.5 ;
replace pimmi3=pimmi3 - 5.5 ;
replace ppriv3=ppriv3 - 5.5 ;
replace palco3=palco3 - 5.5 ;
replace pcrim3=pcrim3 - 5.5 ;

replace plfrt4=plfrt4 - 5.5 ;
replace pagri4=pagri4 - 5.5 ;
replace penvi4=penvi4 - 5.5 ;
replace pimmi4=pimmi4 - 5.5 ;
replace ppriv4=ppriv4 - 5.5 ;
replace palco4=palco4 - 5.5 ;
replace pcrim4=pcrim4 - 5.5 ;

replace plfrt5=plfrt5 - 5.5 ;
replace pagri5=pagri5 - 5.5 ;
replace penvi5=penvi5 - 5.5 ;
replace pimmi5=pimmi5 - 5.5 ;
replace ppriv5=ppriv5 - 5.5 ;
replace palco5=palco5 - 5.5 ;
replace pcrim5=pcrim5 - 5.5 ;

replace plfrt6=plfrt6 - 5.5 ;
replace pagri6=pagri6 - 5.5 ;
replace penvi6=penvi6 - 5.5 ;
replace pimmi6=pimmi6 - 5.5 ;
replace ppriv6=ppriv6 - 5.5 ;
replace palco6=palco6 - 5.5 ;
replace pcrim6=pcrim6 - 5.5 ;

replace plfrt7=plfrt7 - 5.5 ;
replace pagri7=pagri7 - 5.5 ;
replace penvi7=penvi7 - 5.5 ;
replace pimmi7=pimmi7 - 5.5 ;
replace ppriv7=ppriv7 - 5.5 ;
replace palco7=palco7 - 5.5 ;
replace pcrim7=pcrim7 - 5.5 ;


/* Initialize gsymp variables */
gen gsymp1=symp1 ;
gen gsymp2=symp2 ;
gen gsymp3=symp3 ;
gen gsymp4=symp4 ;
gen gsymp5=symp5 ;
gen gsymp6=symp6 ;
gen gsymp7=symp7 ;

/* calculate means */
meancalc plfrt1 mlfrt1;
meancalc pagri1 magri1;
meancalc penvi1 menvi1;
meancalc pimmi1 mimmi1;
meancalc ppriv1 mpriv1;
meancalc palco1 malco1;
meancalc pcrim1 mcrim1;
                      
meancalc plfrt2 mlfrt2;
meancalc pagri2 magri2;
meancalc penvi2 menvi2;
meancalc pimmi2 mimmi2;
meancalc ppriv2 mpriv2;
meancalc palco2 malco2;
meancalc pcrim2 mcrim2;
                      
meancalc plfrt3 mlfrt3;
meancalc pagri3 magri3;
meancalc penvi3 menvi3;
meancalc pimmi3 mimmi3;
meancalc ppriv3 mpriv3;
meancalc palco3 malco3;
meancalc pcrim3 mcrim3;
                      
meancalc plfrt4 mlfrt4;
meancalc pagri4 magri4;
meancalc penvi4 menvi4;
meancalc pimmi4 mimmi4;
meancalc ppriv4 mpriv4;
meancalc palco4 malco4;
meancalc pcrim4 mcrim4;
                      
meancalc plfrt5 mlfrt5;
meancalc pagri5 magri5;
meancalc penvi5 menvi5;
meancalc pimmi5 mimmi5;
meancalc ppriv5 mpriv5;
meancalc palco5 malco5;
meancalc pcrim5 mcrim5;
                      
meancalc plfrt6 mlfrt6;
meancalc pagri6 magri6;
meancalc penvi6 menvi6;
meancalc pimmi6 mimmi6;
meancalc ppriv6 mpriv6;
meancalc palco6 malco6;
meancalc pcrim6 mcrim6;
                      
meancalc plfrt7 mlfrt7;
meancalc pagri7 magri7;
meancalc penvi7 menvi7;
meancalc pimmi7 mimmi7;
meancalc ppriv7 mpriv7;
meancalc palco7 malco7;
meancalc pcrim7 mcrim7;



/* called do routines set to 0 before first call and make first call*/
scalar calldmsm=0;
scalar calldisi=0;

*do c:\stata\do\updatemn;
do c:\stata\do\dmsm ;
do c:\stata\do\disi ;                         


/* set up wide-long data structures */
   reshape j /*groups*/ party 1-7 ;
   reshape xij /*vars*/
      symp gsymp g7symp penalty
      plfrt pagri penvi pimmi ppriv palco pcrim
      p_lfrt p_agri p_envi p_immi p_priv p_alco p_crim
      dilfrt diagri dienvi diimmi dipriv dialco dicrim
      dixlfrt dixagri dixenvi diximmi dixpriv dixalco dixcrim
      silfrt siagri sienvi siimmi sipriv sialco sicrim
      si2lfrt si2agri si2envi si2immi si2priv si2alco si2crim
      plnlfrt plnagri plnenvi plnimmi plnpriv plnalco plncrim
      dmlfrt dmagri dmenvi dmimmi dmpriv dmalco dmcrim
      dmxlfrt dmxagri dmxenvi dmximmi dmxpriv dmxalco dmxcrim
      smlfrt smagri smenvi smimmi smpriv smalco smcrim
      sm2lfrt sm2agri sm2envi sm2immi sm2priv sm2alco sm2crim
      mlnlfrt mlnagri mlnenvi mlnimmi mlnpriv mlnalco mlncrim
     ;
   reshape i /*cons*/
      idnum 
      ;

